package cn.auto.utility;

import java.util.HashMap;
import java.util.List;

public class Status {

	// 定义接口返回status 状态码
	public static final String SUCCESS = "2000";
	public static final String NORECORD = "4004";
	public static final String PSWERROR = "4001"; // 密码与数据库不匹配
	public static final String DUPRECORD = "4002"; // 数据库重复记录
	public static final String FAILED = "5000";
	public static final String VERIFYERROR = "5001";
	public static final String UNKNOWN = "0000";

	public static final String NOTSUCCESS = "errmsg"; // 返回错误信息 ,map key

	public static HashMap<Object, Object> searchResultCode(List<?> infos) {
		HashMap<Object, Object> result = new HashMap<Object, Object>();
		try {
			if (infos.size() > 0) {
				result.put("status", SUCCESS);
				result.put("body", infos);
			} else if (infos.isEmpty()) {
				result.put("status", NORECORD);
			} else {
				result.put("status", FAILED);
			}
		} catch (Exception e) {
			result.put("status", UNKNOWN);
		}
		return result;
	}
	
	public static String booleanResultCode(boolean isTrue) {
		String result = null;
		if (isTrue == true) {
			result = Status.SUCCESS;
		} else {
			result = Status.FAILED;
		}
		return result;
	}
}